// run: $exec < input
#include <iostream>
#include <string>

int const maxn = 100007;
bool vis[maxn];

std::string s;

template <class T>
T abs(T x) { return x < 0 ? -x : x; }

bool judge(std::string const& a, std::string const& b)
{
	std::string::size_type t1 = s.find(a);
	std::string::size_type t2 = s.rfind(b);
	if (t1 == std::string::npos || t2 == std::string::npos)
		return false;
	return (abs((int)t1 - (int)t2) != 1);
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> s;
	if (judge("AB", "BA") || judge("BA", "AB"))
		std::cout << "YES\n";
	else
		std::cout << "NO\n";
}

